import 'package:flutter/material.dart';
import '../models/post_type.dart';

/// 动态类型选择器
class PostTypeSelector extends StatelessWidget {
  final PostType selectedType;
  final ValueChanged<PostType> onTypeChanged;

  const PostTypeSelector({
    super.key,
    required this.selectedType,
    required this.onTypeChanged,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 10,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '选择动态类型',
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w600,
              color: Color(0xFF333333),
            ),
          ),
          const SizedBox(height: 16),
          Row(
            children: PostType.values.map((type) {
              final isSelected = selectedType == type;
              return Expanded(
                child: GestureDetector(
                  onTap: () => onTypeChanged(type),
                  child: Container(
                    margin: const EdgeInsets.only(right: 8),
                    padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
                    decoration: BoxDecoration(
                      color: isSelected ? const Color(0xFF007AFF) : const Color(0xFFF5F5F5),
                      borderRadius: BorderRadius.circular(8),
                      border: Border.all(
                        color: isSelected ? const Color(0xFF007AFF) : Colors.transparent,
                        width: 1,
                      ),
                    ),
                    child: Column(
                      children: [
                        Icon(
                          _getIconData(type),
                          size: 24,
                          color: isSelected ? Colors.white : const Color(0xFF666666),
                        ),
                        const SizedBox(height: 4),
                        Text(
                          type.name,
                          style: TextStyle(
                            fontSize: 12,
                            fontWeight: FontWeight.w500,
                            color: isSelected ? Colors.white : const Color(0xFF666666),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              );
            }).toList(),
          ),
          const SizedBox(height: 8),
          Text(
            selectedType.description,
            style: const TextStyle(
              fontSize: 12,
              color: Color(0xFF999999),
            ),
          ),
        ],
      ),
    );
  }

  IconData _getIconData(PostType type) {
    switch (type) {
      case PostType.text:
        return Icons.text_fields_outlined;
      case PostType.article:
        return Icons.article_outlined;
      case PostType.video:
        return Icons.videocam_outlined;
      case PostType.videoCollection:
        return Icons.video_library_outlined;
      case PostType.service:
        return Icons.store_outlined;
    }
  }
}

